package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 套餐相关接口数据层
 */
@Mapper
public interface SetmealMapper {

    /**
     * 根据分类id查询套餐数量
     * @param categoryId
     * @return
     */
    @Select("select count(*) from setmeal where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 修改套餐状态
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 分页查询套餐
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 添加套餐信息
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    void insert(Setmeal setmeal);

    /**
     * 根据id查询套餐
     * @param setmealId
     * @return
     */
    @Select("select setmeal.* , category.name as categoryName , category.id as categoryId from setmeal left outer join category on setmeal.category_id = category.id where setmeal.id = #{setmealId}")
    SetmealVO getWithCategoryById(Long setmealId);

    /**
     * 根据id查询套餐
     * @param ids
     * @return
     */
    List<Setmeal> getByIds(List<Long> ids);

    /**
     * 批量删除套餐
     * @param ids
     */
    void deleteBatch(List<Long> ids);

    /**
     * 根据分类id查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> getByCategoryId(Setmeal setmeal);

    /**
     * 根据套餐 id 查询菜品信息
     * @param id
     * @return
     */
    @Select("select setmeal_dish.name , setmeal_dish.copies , dish.image , dish.description from setmeal_dish left join dish on setmeal_dish.dish_id = dish.id where setmeal_dish.setmeal_id = #{id}")
    List<DishItemVO> getDishesBySetmealId(Long id);

    /**
     * 根据套餐id查询套餐信息
     * @param setmealId
     */
    @Select("select * from setmeal where id = #{setmealId}")
    Setmeal getById(Long setmealId);

    /**
     * 根据状态查询套餐数量
     * @param status
     * @return
     */
    @Select("select count(*) from setmeal where status = #{status}")
    Integer countByStatus(Integer status);
}
